package x.y.z;

import java.util.HashSet;
import java.util.Set;

public class Interview_2_1_RemoveDups {
    public ListNode removeDuplicateNodes(ListNode head) {
        Set<Integer> set = new HashSet<>();
        ListNode prev = null;
        ListNode curr = head;
        while (curr != null) {
            if (set.contains(curr.val)) {
                prev.next = curr.next;
                curr = curr.next;
            } else {
                set.add(curr.val);
                prev = curr;
            }
        }
        return head;
    }
}
